package kr.ac.kaist.pointdaproject;

import java.util.List;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;

public class WifiInformation {

	private WifiManager wifiManager;
	private ConnectivityManager connManager;
	
	private String BestWifi_SSID;
	private int BestWifi_Level;
	
	public WifiInformation(){
		super();
	}
	
	public WifiInformation(Context c){
		wifiManager = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
		connManager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
		
		NetworkInfo wifiInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
		
		int Wifi_level = -100;	// set worst strength
		int position = 0;
		
		if(wifiInfo.isAvailable())
		{
			List<ScanResult> wifiList = wifiManager.getScanResults();
			
			for(int i=0; i<wifiList.size(); i++)
			{
				if(Wifi_level < wifiList.get(i).level)
				{
					Wifi_level = wifiList.get(i).level;
					position = i;
				}
				
			}
			
			BestWifi_SSID = wifiList.get(position).SSID;
			BestWifi_Level = wifiList.get(position).level;
		}
		else
		{
			BestWifi_SSID = "default";
			BestWifi_Level = -100;
		}
	}

	public String getBestWifiSSID(){
		return BestWifi_SSID;
	}

	public int getBestWifiLevel(){
		return BestWifi_Level;
	}	

}
